<template>
  <nav class="navbar">
    <div class="navbar-left">
      <img src="../../assets/icon/logo.svg" alt="" />
      <a href="#" class="title" @click="handleRoam()">光谷智慧交通</a>
    </div>
    <div class="navbar-middle">
      <ul class="nav-links">
        <!-- 普通用户组件 -->
        <AddEvent></AddEvent>
        <RealTimeMap />
        <search-event v-if="isTrafficManageUser"></search-event>
        <my-event></my-event>
        <ViewNotice></ViewNotice>
        <tools-box></tools-box>
        <!-- 交管用户组件 -->
        <VideoWatch v-if="isTrafficManageUser"></VideoWatch>
        <TrafficEventManage v-if="isTrafficManageUser" />
        <map-notice v-if="isTrafficManageUser"></map-notice>
      </ul>
    </div>
    <!-- 登录组件 -->
    <div class="navbar-right">
      <UserIsLogin v-if="isLogin" @out="handleOutLogin" />
      <UserNoLogin v-else />
    </div>
  </nav>
</template>

<script setup>
import { prototype } from '../../main'
import MapNotice from '../MapNotice/MapNotice.vue'
import ViewNotice from '../MapNotice/components/ViewNotice/ViewNotice.vue'
import AddEvent from '../AddEvent/AddEvent.vue'
import ToolsBox from './components/ToolsBox/ToolsBox.vue'
import SearchEvent from './components/SearchEvent/SearchEvent.vue'
import UserIsLogin from './components/UserInfo/UserIsLogin.vue'
import UserNoLogin from './components/UserInfo/UserNoLogin.vue'
import { putUserIsLoginHttp } from '../../request/userHttp'
import RealTimeMap from './components/RealTimeMap/RealTimeMap.vue'
import TrafficEventManage from './components/TrafficEventManage/TrafficEventManage.vue'
import { userModules } from '../../stores/userModulsStore'
import MyEvent from './components/MyEvent/MyEvent.vue'
import VideoWatch from './components/VideoWatch/VideoWatch.vue'

const isTrafficManageUser = ref(false)
const isLogin = ref(false)
const { userLoginData } = userModules()
onMounted(async () => {
  if (userLoginData.value.user_role) {
    isTrafficManageUser.value = true
  }
  if (userLoginData.value.id) {
    isLogin.value = true
  } else {
    isLogin.value = false
  }
})

const handleOutLogin = (userId) => {
  const userLoginData = []
  localStorage.setItem('userLoginData', JSON.stringify(userLoginData))
  putUserIsLoginHttp(userId, 0)
  isLogin.value = false
  // localStorage.removeItem('token')
}
function handleRoam() {
  const view = prototype.$map.getView()
  view.animate({
    center: [114.37, 30.5],
    zoom: 13.5,
    duration: 1000
  })
}
</script>

<style lang="less" scoped>
.navbar {
  position: absolute;
  top: 0;
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 1200px;
  height: 60px;
  min-height: 60px;
  background: linear-gradient(to top, rgba(255, 255, 255, 0.7) 60%, rgba(255, 255, 255, 1) 100%);
  padding: 0 10px;
  box-sizing: border-box;
}

span {
  cursor: pointer;
}
.navbar-left {
  width: 180px;
  min-width: 180px;
  img {
    width: 30px;
    height: 30px;
    margin-right: 8px;
  }
  display: flex;
  align-items: center;
}
.title {
  font-family: Arial, sans-serif;
  font-size: 20px;
  font-weight: bold;
  color: #333;
  text-decoration: none;
  text-shadow: 1px 1px 1px #ccc;
  transition: all 0.3s ease;
}
.title:hover {
  color: #666;
  text-shadow: 2px 2px 2px #ccc;
}

.navbar-middle {
  flex: 1;
  display: flex;
  align-items: center;
  height: 100%;
  :deep(img) {
    margin-right: 5px;
    vertical-align: middle;
    cursor: pointer;
    transform: rotate(90deg);
    transition: all 0.5s;
  }
}

.nav-links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  height: 100%;
  margin: 0;
  padding: 0;
  background-color: transparent;
}

:deep(li) {
  margin-right: 10px !important;
  min-width: 70px;
}

.nav-links li {
  margin-right: 20px;
}

.my-event {
  position: relative;
  .event-count {
    position: absolute;
    top: -4px;
    right: -8px;
    width: 10px;
    height: 10px;
    text-align: center;
    line-height: 10px;
    color: #fff;
    background-color: red;
    border-radius: 50%;
  }
}

.notice {
  position: relative;
  margin-top: -5px;
}

.nav-links a {
  font-size: 16px;
  color: #333;
  text-decoration: none;
}

.dropdown {
  position: relative;
}

.dropdown-content {
  position: absolute;
  top: 100%;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100px;
  margin-top: 10px;
  background-color: #fff;
  border-radius: 0 0 5px 5px;
  span {
    margin: 5px;
    font-size: 15px;
  }
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 160px;
  height: 50px;
  border: none;
  text-align: center;
  font-size: 16px;
  cursor: pointer;
  border-radius: 20px;
  box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.4);
}
// .user-info {
//   display: flex;
//   align-items: center;
//   justify-content: center;
//   width: 160px;
//   height: 50px;
//   border: none;
//   text-align: center;
//   font-size: 16px;
//   cursor: pointer;
//   border-radius: 20px;
//   box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.25);
// }

.user-nickname {
  font-size: 16px;
  color: #333;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: #ccc;
}

// .login-btn {
//   display: flex;
//   width: 160px;
//   .sign-in {
//     width: 50%;
//     background-color: #ffc107;
//     color: white;
//     border: none;
//     padding: 10px 20px;
//     text-align: center;
//     text-decoration: none;
//     display: inline-block;
//     font-size: 16px;
//     margin: 4px 2px;
//     cursor: pointer;
//     border-radius: 20px;
//     box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.25);
//   }
//   .sign-up {
//     width: 50%;
//     background-color: #4caf50;
//     color: white;
//     border: none;
//     padding: 10px 20px;
//     text-align: center;
//     text-decoration: none;
//     display: inline-block;
//     font-size: 16px;
//     margin: 4px 2px;
//     cursor: pointer;
//     border-radius: 20px;
//     box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.25);
//   }
// }
</style>
